package com.ruoyi.web.controller.shop;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.domain.Sell;
import com.ruoyi.shop.service.ISellService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售管理Controller
 * 
 * @author ruoyi
 * @date 2024-06-07
 */
@RestController
@RequestMapping("/shop/sell")
public class SellController extends BaseController
{
    @Autowired
    private ISellService sellService;

    /**
     * 查询销售管理列表
     */
    @PreAuthorize("@ss.hasPermi('shop:sell:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sell sell)
    {
        startPage();
        List<Sell> list = sellService.selectSellList(sell);
        return getDataTable(list);
    }

    @GetMapping("/list2")
    public TableDataInfo list2(Sell sell)
    {

        List<Sell> list = sellService.selectSellList2(sell);
        return getDataTable(list);
    }

    /**
     * 导出销售管理列表
     */
    @PreAuthorize("@ss.hasPermi('shop:sell:export')")
    @Log(title = "销售管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sell sell)
    {
        List<Sell> list = sellService.selectSellList(sell);
        ExcelUtil<Sell> util = new ExcelUtil<Sell>(Sell.class);
        util.exportExcel(response, list, "销售管理数据");
    }

    /**
     * 获取销售管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:sell:query')")
    @GetMapping(value = "/{sellId}")
    public AjaxResult getInfo(@PathVariable("sellId") Long sellId)
    {
        return success(sellService.selectSellBySellId(sellId));
    }

    /**
     * 新增销售管理
     */
    @PreAuthorize("@ss.hasPermi('shop:sell:add')")
    @Log(title = "销售管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Sell sell)
    {
        return toAjax(sellService.insertSell(sell));
    }

    /**
     * 修改销售管理
     */
    @PreAuthorize("@ss.hasPermi('shop:sell:edit')")
    @Log(title = "销售管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sell sell)
    {
        return toAjax(sellService.updateSell(sell));
    }

    /**
     * 删除销售管理
     */
    @PreAuthorize("@ss.hasPermi('shop:sell:remove')")
    @Log(title = "销售管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sellIds}")
    public AjaxResult remove(@PathVariable Long[] sellIds)
    {
        return toAjax(sellService.deleteSellBySellIds(sellIds));
    }
}
